home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / svgakt50.zip / SRC / SVGAKIT / SVGATEST.C < prev    next >
C/C++ Source or Header  |  1994-08-23  |  17KB  |  597 lines

  1. /****************************************************************************
  2. *
  3. *                              The SuperVGA Kit
  4. *
  5. *                   Copyright (C) 1994 SciTech Software
  6. *                           All rights reserved.
  7. *
  8. * Filename:     $RCSfile: svgatest.c $
  9. * Version:      $Revision: 1.1 $
  10. *
  11. * Language:     ANSI C
  12. * Environment:  IBM PC (MSDOS) Real Mode and 16/32 bit Protected Mode.
  13. *
  14. * Description:  Simple program to test the operation of the SuperVGA
  15. *               bank switching code and page flipping code for the
  16. *               all supported video modes.
  17. *
  18. *               MUST be compiled in the large or flat models.
  19. *
  20. * $Id: svgatest.c 1.1 1994/08/22 12:27:00 kjb release $
  21. *
  22. ****************************************************************************/
  23.  
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <string.h>
  27. #include <dos.h>
  28. #include <conio.h>
  29. #include "pmode.h"
  30. #include "svga.h"
  31.  
  32. /*---------------------------- Global Variables ---------------------------*/
  33.  
  34. int     x,y;
  35.  
  36. /* External routines */
  37.  
  38. #ifdef    REALMODE
  39. void _cdecl _copyTest256(void);
  40. void _cdecl _copyTest16(void);
  41. #endif
  42.  
  43. int _cdecl queryCpu(void);
  44.  
  45. #include "version.c"
  46.  
  47. /*----------------------------- Implementation ----------------------------*/
  48.  
  49. void clearText(void)
  50. /****************************************************************************
  51. *
  52. * Function:     clearText
  53. *
  54. * Description:  Clears the current text display mode.
  55. *
  56. ****************************************************************************/
  57. {
  58.     RMREGS    regs;
  59.  
  60.     regs.x.cx = 0;
  61.     regs.h.dl = 80;
  62.     regs.h.dh = 50;
  63.     regs.h.ah = 0x06;
  64.     regs.h.al = 50;
  65.     regs.h.bh = 0x07;
  66.     PM_int86(0x10,®s,®s);      /* Scroll display up    */
  67.     regs.x.dx = 0;
  68.     regs.h.bh = 0;
  69.     regs.h.ah = 0x02;
  70.     PM_int86(0x10,®s,®s);      /* Home the cursor      */
  71. }
  72.  
  73. void moireTest(void)
  74. /****************************************************************************
  75. *
  76. * Function:     moireTest
  77. *
  78. * Description:  Draws a simple Moire pattern on the display screen using
  79. *               lines, and waits for a key press.
  80. *
  81. ****************************************************************************/
  82. {
  83.     char    buf[80];
  84.     int     i;
  85.     uint    value;
  86.  
  87.     clear(0);
  88.     if (maxcolor >= 0x7FFFL) {
  89.         for (i = 0; i < maxx; i++) {
  90.             line(maxx/2,maxy/2,i,0,rgbColor((uchar)((i*255L)/maxx),0,0));
  91.             line(maxx/2,maxy/2,i,maxy,rgbColor(0,(uchar)((i*255L)/maxx),0));
  92.             }
  93.         for (i = 0; i < maxy; i++) {
  94.             value = (i*255L)/maxy;
  95.             line(maxx/2,maxy/2,0,i,rgbColor((uchar)value,0,(uchar)(255 - value)));
  96.             line(maxx/2,maxy/2,maxx,i,rgbColor(0,(uchar)(255 - value),(uchar)value));
  97.             }
  98.         }
  99.     else {
  100.         for (i = 0; i < maxx; i += 5) {
  101.             line(maxx/2,maxy/2,i,0,i % maxcolor);
  102.             line(maxx/2,maxy/2,i,maxy,(i+1) % maxcolor);
  103.             }
  104.         for (i = 0; i < maxy; i += 5) {
  105.             line(maxx/2,maxy/2,0,i,(i+2) % maxcolor);
  106.             line(maxx/2,maxy/2,maxx,i,(i+3) % maxcolor);
  107.             }
  108.         }
  109.     line(0,0,maxx,0,defcolor);
  110.     line(0,0,0,maxy,defcolor);
  111.     line(maxx,0,maxx,maxy,defcolor);
  112.     line(0,maxy,maxx,maxy,defcolor);
  113.  
  114.     if (maxx != 319) {
  115.         x = 80;
  116.         y = 80;
  117.         writeText(x,y,"Bank switching test",defcolor);  y += 32;
  118.         sprintf(buf,"Video mode: %d x %d %ld color",maxx+1,maxy+1, maxcolor+1);
  119.         writeText(x,y,buf,defcolor);    y += 16;
  120.         sprintf(buf,"Maximum x: %d, Maximum y: %d, BytesPerLine %d, Pages: %d",
  121.             maxx,maxy,bytesperline,maxpage+1);
  122.         writeText(x,y,buf,defcolor);    y += 32;
  123.         writeText(x,y,"You should see a colorful Moire pattern on the screen",defcolor);
  124.         y += 16;
  125.         }
  126.     else {
  127.         x = 40;
  128.         y = 40;
  129.         }
  130.     writeText(x,y,"Press any key to continue",defcolor);
  131.     y += 32;
  132.     getch();
  133. }
  134.  
  135. void readWriteTest(void)
  136. /****************************************************************************
  137. *
  138. * Function:     readWriteTest
  139. *
  140. * Description:  Test the separate read/write bank routines if available.
  141. *               We do this by copying the top 100 scanlines of video memory
  142. *               to another location in video memory.
  143. *
  144. *               This test is desgined to work only in 640 wide video modes.
  145. *
  146. ****************************************************************************/
  147. {
  148. #ifdef    REALMODE
  149.     if (twobanks && maxpage != 0 && (maxx == 799) && (maxcolor == 15)) {
  150.         writeText(x,y,"To test the separate read/write banks, the top half of",defcolor);
  151.         y += 16;
  152.         writeText(x,y,"this display page should be moved to the bottom half of",defcolor);
  153.         y += 16;
  154.         writeText(x,y,"the second display page",defcolor);
  155.         setActivePage(1);
  156.         clear(0);
  157.         setVisualPage(1);
  158.         _copyTest16();
  159.         x = y = 80;
  160.         writeText(x,y,"Press any key to continue",defcolor);
  161.         getch();
  162.         }
  163.     if (twobanks && (maxx == 639) && (maxcolor == 255)) {
  164.         _copyTest256();
  165.         writeText(x,y,"To test the separate read/write banks, the top 100 scanlines of",defcolor);
  166.         y += 16;
  167.         writeText(x,y,"this display page should be moved to start at scanline 205.",defcolor);
  168.         y += 16;
  169.         writeText(x,y,"This ensures that a bank boundary will have been crossed",defcolor);
  170.         y += 78;
  171.         writeText(x,y,"Press any key to continue",defcolor);
  172.         getch();
  173.         }
  174. #endif
  175. }
  176.  
  177. void pageFlipTest(void)
  178. /****************************************************************************
  179. *
  180. * Function:     pageFlipTest
  181. *
  182. * Description:  Animates a line on the display using page flipping if
  183. *               page flipping is active.
  184. *
  185. ****************************************************************************/
  186. {
  187.     int     i,j,istep,jstep,color,apage,vpage;
  188.     char    buf[80];
  189.  
  190.     if (maxpage != 0) {
  191.         vpage = 0;
  192.         apage = 1;
  193.         setActivePage(apage);
  194.         setVisualPage(vpage);
  195.         i = 0;
  196.         j = maxy;
  197.         istep = 2;
  198.         jstep = -2;
  199.         color = 15;
  200.         if (maxcolor > 255)
  201.             color = maxcolor;
  202.         while (!kbhit()) {
  203.             setActivePage(apage);
  204.             clear(0);
  205.             sprintf(buf,"Page %d of %d", apage+1, maxpage+1);
  206.             if (maxx == 319) {
  207.                 writeText(0,80,"Page flipping - should be no flicker",defcolor);
  208.                 writeText(0,100,buf,defcolor);
  209.                 }
  210.             else {
  211.                 writeText(80,80,"Page flipping - should be no flicker",defcolor);
  212.                 writeText(80,100,buf,defcolor);
  213.                 }
  214.             line(i,0,maxx-i,maxy,color);
  215.             line(0,maxy-j,maxx,j,color);
  216.             line(0,0,maxx,0,defcolor);
  217.             line(0,0,0,maxy,defcolor);
  218.             line(maxx,0,maxx,maxy,defcolor);
  219.             line(0,maxy,maxx,maxy,defcolor);
  220.             vpage = ++vpage % (maxpage+1);
  221.             setVisualPage(vpage);
  222.             apage = ++apage % (maxpage+1);
  223.             i += istep;
  224.             if (i > maxx) {
  225.                 i = maxx-2;
  226.                 istep = -2;
  227.                 }
  228.             if (i < 0)  i = istep = 2;
  229.             j += jstep;
  230.             if (j > maxy) {
  231.                 j = maxy-2;
  232.                 jstep = -2;
  233.                 }
  234.             if (j < 0)  j = jstep = 2;
  235.             }
  236.         getch();                /* Swallow keypress */
  237.         }
  238. }
  239.  
  240. void wideDACTest(void)
  241. /****************************************************************************
  242. *
  243. * Function:        wideDACTest
  244. *
  245. * Description:  Displays a set of color values using the wide DAC support
  246. *                if available.
  247. *
  248. ****************************************************************************/
  249. {
  250.     int        i;
  251.     palette    pal[256];
  252.  
  253.     if (widedac) {
  254.         if (!set8BitPalette()) return;
  255.  
  256.         memset(pal,0,256*3);
  257.         for (i = 0; i < 256; i += 4) {
  258.             pal[64 + (i >> 2)].red = i;
  259.             pal[128 + (i >> 2)].green = i;
  260.             pal[192 + (i >> 2)].blue = i;
  261.             }
  262.  
  263.         pal[defcolor].red = 255;
  264.         pal[defcolor].green = 255;
  265.         pal[defcolor].blue = 255;
  266.         setPalette(0,256,pal);
  267.  
  268.         clear(0);
  269.         line(0,0,maxx,0,defcolor);
  270.         line(0,0,0,maxy,defcolor);
  271.         line(maxx,0,maxx,maxy,defcolor);
  272.         line(0,maxy,maxx,maxy,defcolor);
  273.  
  274.         if (maxx != 319) {
  275.             x = 80;
  276.             y = 80;
  277.             }
  278.         else {
  279.             x = 40;
  280.             y = 40;
  281.             }
  282.  
  283.         writeText(x,y,"Wide DAC test",defcolor);
  284.         y += 32;
  285.         if (maxx != 319) {
  286.             writeText(x,y,"You should see a smooth transition of colors",defcolor);
  287.             y += 16;
  288.             writeText(x,y,"If the colors are broken into 4 lots, the wide DAC is not working",defcolor);
  289.             y += 32;
  290.             }
  291.  
  292.         for (i = 0; i < 192; i++) {
  293.             line(x+i, y,    x+i, y+32,  64+i/3);
  294.             line(x+i, y+32, x+i, y+64,  128+i/3);
  295.             line(x+i, y+64, x+i, y+96,  192+i/3);
  296.             }
  297.  
  298.         getch();
  299.         set6BitPalette();
  300.         }
  301. }
  302.  
  303. void testingComplete(void)
  304. /****************************************************************************
  305. *
  306. * Function:     testingComplete
  307. *
  308. * Description:  Clears the first display page and puts up a message.
  309. *
  310. ****************************************************************************/
  311. {
  312.     setActivePage(0);
  313.     setVisualPage(0);
  314.     clear(0);
  315.  
  316.     if (maxx == 319) {
  317.         writeText(0,40,"Testing complete",defcolor);
  318.         writeText(0,60,"press any key to return to text mode",defcolor);
  319.         }
  320.     else
  321.         writeText(80,80,"Testing complete - press any key to return to text mode",defcolor);
  322.     getch();
  323. }
  324.  
  325. void test16(void)
  326. {
  327.     int     i,choice,maxmenu;
  328.     int     xres,yres,bitsperpixel,memmodel,maxpage;
  329.     long    pagesize;
  330.     int     menu[10];
  331.  
  332.     while (true) {
  333.         clearText();
  334.         printf("16 color tests\n\n");
  335.         printf("Which video mode to test:\n\n");
  336.  
  337.         maxmenu = 0;
  338.  
  339.         /* Add standard VGA modes to menu */
  340.  
  341.         getSuperVGAModeInfo(menu[maxmenu] = 0x0D,&xres,&yres,&bytesperline,
  342.                 &bitsperpixel,&memmodel,&maxpage,&pagesize);
  343.         printf("    [%d] - %d x %d 16 color (%d page)\n",maxmenu++,
  344.             xres,yres,maxpage+1);
  345.  
  346.         getSuperVGAModeInfo(menu[maxmenu] = 0x0E,&xres,&yres,&bytesperline,
  347.                 &bitsperpixel,&memmodel,&maxpage,&pagesize);
  348.         printf("    [%d] - %d x %d 16 color (%d page)\n",maxmenu++,
  349.             xres,yres,maxpage+1);
  350.  
  351.         getSuperVGAModeInfo(menu[maxmenu] = 0x10,&xres,&yres,&bytesperline,
  352.                 &bitsperpixel,&memmodel,&maxpage,&pagesize);
  353.         printf("    [%d] - %d x %d 16 color (%d page)\n",maxmenu++,
  354.             xres,yres,maxpage+1);
  355.  
  356.         getSuperVGAModeInfo(menu[maxmenu] = 0x12,&xres,&yres,&bytesperline,
  357.                 &bitsperpixel,&memmodel,&maxpage,&pagesize);
  358.         printf("    [%d] - %d x %d 16 color (%d page)\n",maxmenu++,
  359.             xres,yres,maxpage+1);
  360.  
  361.         for (i = 0; modeList[i] != -1; i++) {
  362.             /* Filter out the 256 color packed pixel video modes */
  363.  
  364.             if (!getSuperVGAModeInfo(modeList[i],&xres,&yres,&bytesperline,
  365.                     &bitsperpixel,&memmodel,&maxpage,&pagesize))
  366.                 continue;
  367.             if ((bitsperpixel == 4) && (memmodel == memPL)) {
  368.                 printf("    [%d] - %d x %d 16 color (%d page)\n",maxmenu,
  369.                     xres,yres,maxpage+1);
  370.                 menu[maxmenu++] = modeList[i];
  371.                 }
  372.             }
  373.         printf("    [Q] - Quit\n\n");
  374.         printf("Choice: ");
  375.         fflush(stdout);
  376.  
  377.         choice = getch();
  378.         if (choice == 'q' || choice == 'Q' || choice == 0x1B)
  379.             break;
  380.         choice -= '0';
  381.         if (0 <= choice && choice < maxmenu) {
  382.             if (!setSuperVGAMode(menu[choice])) {
  383.                 printf("\n");
  384.                 printf("ERROR: Video mode did not set correctly!\n\n");
  385.                 printf("\nPress any key to continue...\n");
  386.                 getch();
  387.                 }
  388.             else {
  389.                 moireTest();
  390.                 readWriteTest();
  391.                 pageFlipTest();
  392.                 testingComplete();
  393.                 restoreMode();
  394.                 }
  395.             }
  396.         }
  397. }
  398.  
  399. void test256(void)
  400. {
  401.     int     i,choice,maxmenu;
  402.     int     xres,yres,bitsperpixel,memmodel,maxpage;
  403.     long    pagesize;
  404.     int     menu[10];
  405.  
  406.     while (true) {
  407.         clearText();
  408.         printf("256 color tests\n\n");
  409.         printf("Which video mode to test:\n\n");
  410.  
  411.         maxmenu = 0;
  412.  
  413.         /* Add standard VGA modes to menu */
  414.  
  415.         getSuperVGAModeInfo(menu[maxmenu] = 0x13,&xres,&yres,&bytesperline,
  416.                 &bitsperpixel,&memmodel,&maxpage,&pagesize);
  417.         printf("    [%d] - %d x %d 256 color (%d page)\n",maxmenu++,
  418.             xres,yres,maxpage+1);
  419.  
  420.         for (i = 0; modeList[i] != -1; i++) {
  421.             /* Filter out the 256 color packed pixel video modes */
  422.  
  423.             if (!getSuperVGAModeInfo(modeList[i],&xres,&yres,&bytesperline,
  424.                     &bitsperpixel,&memmodel,&maxpage,&pagesize))
  425.                 continue;
  426.             if ((bitsperpixel == 8) && (memmodel == memPK)) {
  427.                 printf("    [%d] - %d x %d 256 color (%d page)\n",maxmenu,
  428.                     xres,yres,maxpage+1);
  429.                 menu[maxmenu++] = modeList[i];
  430.                 }
  431.             }
  432.         printf("    [Q] - Quit\n\n");
  433.         printf("Choice: ");
  434.         fflush(stdout);
  435.  
  436.         choice = getch();
  437.         if (choice == 'q' || choice == 'Q' || choice == 0x1B)
  438.             break;
  439.         choice -= '0';
  440.         if (0 <= choice && choice < maxmenu) {
  441.             if (!setSuperVGAMode(menu[choice])) {
  442.                 printf("\n");
  443.                 printf("ERROR: Video mode did not set correctly!\n\n");
  444.                 printf("\nPress any key to continue...\n");
  445.                 getch();
  446.                 }
  447.             else {
  448.                 moireTest();
  449.                 readWriteTest();
  450.                 wideDACTest();
  451.                 pageFlipTest();
  452.                 testingComplete();
  453.                 restoreMode();
  454.                 }
  455.             }
  456.         }
  457. }
  458.  
  459. void testDirectColor(long colors)
  460. {
  461.     int     i,choice,maxmenu,numbits;
  462.     int     xres,yres,bitsperpixel,memmodel,maxpage;
  463.     long    pagesize;
  464.     int     menu[10];
  465.  
  466.     while (true) {
  467.         clearText();
  468.         printf("%ld color tests\n\n", colors+1);
  469.         printf("Which video mode to test:\n\n");
  470.  
  471.         if (colors == 0x7FFFL)
  472.             numbits = 15;
  473.         else if (colors == 0xFFFFL)
  474.             numbits = 16;
  475.         else numbits = 24;
  476.  
  477.         maxmenu = 0;
  478.  
  479.         for (i = 0; modeList[i] != -1; i++) {
  480.             /* Filter out the appropriate video modes */
  481.  
  482.             if (!getSuperVGAModeInfo(modeList[i],&xres,&yres,&bytesperline,
  483.                     &bitsperpixel,&memmodel,&maxpage,&pagesize))
  484.                 continue;
  485.             if (bitsperpixel == numbits || (numbits == 24 && bitsperpixel == 32)) {
  486.                 printf("    [%d] - %d x %d %ld color (%d page)\n",maxmenu,
  487.                     xres,yres,colors+1,maxpage+1);
  488.                 menu[maxmenu++] = modeList[i];
  489.                 }
  490.             }
  491.         printf("    [Q] - Quit\n\n");
  492.         printf("Choice: ");
  493.         fflush(stdout);
  494.  
  495.         choice = getch();
  496.         if (choice == 'q' || choice == 'Q' || choice == 0x1B)
  497.             break;
  498.         choice -= '0';
  499.         if (0 <= choice && choice < maxmenu) {
  500.             if (!setSuperVGAMode(menu[choice])) {
  501.                 printf("\n");
  502.                 printf("ERROR: Video mode did not set correctly!\n\n");
  503.                 printf("\nPress any key to continue...\n");
  504.                 getch();
  505.                 }
  506.             else {
  507.                 moireTest();
  508.                 pageFlipTest();
  509.                 testingComplete();
  510.                 restoreMode();
  511.                 }
  512.             }
  513.         }
  514. }
  515.  
  516. int main(void)
  517. {
  518.     int     vbever, choice,highspeed = false;
  519.     RMREGS  regs;
  520.  
  521.     if (queryCpu() < 4) {
  522.         printf("This program contains '386 specific instructions, and will not work on\n");
  523.         printf("this machine - sorry\n");
  524.         }
  525.  
  526.     if ((vbever = initSuperVGA(true)) < 0x102) {
  527.         printf("This program requires a VESA VBE 1.2 compatible SuperVGA. Try installing\n");
  528.         printf("the Universal VESA VBE for your video card, or contact your video card\n");
  529.         printf("vendor and ask for a suitable TSR\n");
  530.         exit(1);
  531.         }
  532.  
  533.     if (_PM_modeType == PM_386) {
  534.         /* Determine if the UniVBE's high speed protected mode interface is
  535.          * there and functioning, simply so we can report this to the user.
  536.          */
  537.  
  538.         regs.x.ax = 0x4F0A;
  539.         regs.x.bx = 0xFE01;
  540.         regs.x.dx = 0x0500;
  541.         PM_int86(0x10, ®s, ®s);
  542.         if (regs.x.ax == 0x004F)
  543.             highspeed = true;
  544.         }
  545.  
  546.     while (true) {
  547.         clearText();
  548.         printf("The SuperVGA Kit test program (Version %s)\n",version);
  549.         printf("Copyright (C) 1994 SciTech Software - All Rights Reserved\n\n");
  550.         printf("Currently running in ");
  551.         switch (_PM_modeType) {
  552.             case PM_realMode:
  553.                 printf("16 bit real mode\n\n");
  554.                 break;
  555.             case PM_286:
  556.                 printf("16 bit protected mode\n\n");
  557.                 break;
  558.             case PM_386:
  559.                 printf("32 bit protected mode\n\n");
  560.                 break;
  561.             }
  562.  
  563.         printf("VBE OEM string: %s\n",OEMString);
  564.         printf("VBE Version:    %d.%d\n", vbever >> 8, vbever & 0xFF);
  565.         printf("Memory:         %dk\n",memory);
  566.         printf("\n");
  567.         printf("Separate read/write banks:                  %s\n", twobanks ? "Yes" : "No");
  568.         printf("Extended page flipping:                     %s\n", extendedflipping ? "Yes" : "No");
  569.         printf("8 bit wide DAC support:                     %s\n", widedac ? "Yes" : "No");
  570.         printf("Using high speed protected mode interface:  %s\n", highspeed ? "Yes" : "No");
  571.         printf("\n");
  572.         printf("Select color mode to test:\n\n");
  573.         printf("    [0] - 16 color modes\n");
  574.         printf("    [1] - 256 color modes\n");
  575.         printf("    [2] - 32,768 color modes\n");
  576.         printf("    [3] - 65,536 color modes\n");
  577.         printf("    [4] - 16,777,216 color modes\n");
  578.         printf("    [Q] - Quit\n\n");
  579.         printf("Choice: ");
  580.         fflush(stdout);
  581.  
  582.         choice = getch();
  583.         if (choice == 'q' || choice == 'Q' || choice == 0x1B)
  584.             break;
  585.  
  586.         switch (choice) {
  587.             case '0':    test16();                    break;
  588.             case '1':    test256();                    break;
  589.             case '2':    testDirectColor(0x7FFFL);    break;
  590.             case '3':    testDirectColor(0xFFFFL);    break;
  591.             case '4':    testDirectColor(0xFFFFFFL);    break;
  592.             }
  593.         }
  594.     printf("\n");
  595.     return 0;
  596. }
  597.